ctype_punct
检查任何非空白字符或字母数字字符的可打印字符
PHP 4, PHP 5, PHP 7, PHP 8
ctype_punct 函数用于检测一个字符串是否只包含标点字符。如果字符串中包含除标点字符以外的任何字符,则返回 false;如果字符串只包含标点字符,则返回 true。
bool ctype_punct(string $text);
$text (string): 需要检查的字符串。
返回布尔值:如果字符串只包含标点字符,返回 true;否则返回 false。
$text1 = "!?.,"; $text2 = "Hello, world!"; <p>var_dump(ctype_punct($text1)); // 输出 true<br> var_dump(ctype_punct($text2)); // 输出 false<br>
在上面的代码中,$text1 是一个由标点符号组成的字符串,因此 ctype_punct 函数返回 true。而 $text2 包含了字母字符,因此函数返回 false。